
#define KONAMI_CPU_NAME "K052001"

class IKonamiCPUCallbacks abstract {
	public:
		virtual void KonamiSetlines(int lines) = 0;
};

#define KONAMI_IRQ_LINE	0	/* IRQ line number */
#define KONAMI_FIRQ_LINE 1   /* FIRQ line number */

// these have to go here k
#define RM(cs,Addr)				this->mmu->Read8(Addr)
#define WM(cs,Addr,Value)		this->mmu->Write8(Addr,Value)
#define ROP(cs,Addr)			this->mmu->ReadOp8(Addr)
#define ROP_ARG(cs,Addr)		this->mmu->Read8(Addr)

class CKonamiCPU : public CBaseCPU {
	private:
			PAIR	pc; 		/* Program counter */
			PAIR    ppc;        /* Previous program counter */
			PAIR    d;          /* Accumulator a and b */
			PAIR    dp;         /* Direct Page register (page in MSB) */
			PAIR	u, s;		/* Stack pointers */
			PAIR	x, y;		/* Index registers */
			PAIR 	ea;
			UINT8   cc;
			UINT8	ireg;
			UINT8   irq_state[2];

			UINT8   int_state;  /* SYNC and CWAI flags */
			UINT8	nmi_state;
			UINT8	nmi_pending;
			int		icount;
			int     clk;		// Clock Rate
			CBaseMMU* mmu;
			IKonamiCPUCallbacks* callbacks;

	private: // OPTABLES!!! ZOMG
		void (CKonamiCPU::*konami_main[0x100])();
		void (CKonamiCPU::*konami_indexed[0x100])();
		void (CKonamiCPU::*konami_direct[0x100])();
		void (CKonamiCPU::*konami_extended[0x100])();

		// opcode prototypes
		#include "Konami_Optables.h"

	private: // Stuff
			INLINE UINT32 RM16( UINT32 Addr ) {
					UINT32 result = RM(NULL, Addr) << 8;
					return result | RM(NULL, (Addr+1)&0xffff);
			}

			INLINE void WM16 (UINT32 Addr, PAIR *p ) {
					WM(NULL,  Addr, p->b.h );
					WM(NULL,  (Addr+1)&0xffff, p->b.l );
			}

			void CheckIRQs();



	public: // Stuff new to this CPU
		void SetCallbacks(IKonamiCPUCallbacks* cb) { this->callbacks = cb; }

	public:	// From ICpu
			int  Init(int clk);
			void  AssignMMU(int slot, CBaseMMU* mmu);
			int  Exec(int cycles);
			
			void Interrupt(int line, int state);
			void Interrupt(int line, int state, int vector); // IRQ w/ vector.
			void Reset();
			int GetClock();
};
